package com.nju.graphx
import java.sql.ResultSet
import scala.collection.mutable.ListBuffer

/**
 * 存储层：进行处理后的图数据入库、持久化
 *
 * @authorliyunfei
 * @date2022/12/11
 * */
object GraphxDataServiceMySql extends AnyRef with IGraphxDataService{
  val userRecommendSql = "INSERT INTO graphx_user_recommend(user_id,recommend_ids) VALUES(?,?)";
  val usersQuerySql = "select distinct user_id, user_name, follows_id from user where user_name is not null;"
  val userRepoSql = "select distinct r.user_id, user_name, repo_name from user_repo r left join user u on r.user_id = u.user_id where user_name is not null order by r.user_id;"

  /**
   * 查询用户仓库集（来源数据：DB and File(HDFS,))
   *
   * @return
   */
  override def queryUserRepos(): ResultSet = {
           JdbcUtil.query(userRepoSql)
  }

  /**
   * 查询用户集（来源数据：DB and File(HDFS,))
   *
   * @return
   */
  override def queryUsers(): ResultSet = {
           JdbcUtil.query(usersQuerySql)
  }


  /**
   * 单次插入参数
   *
   * @param args
   */
  override def storageUserRecommend(args: ListBuffer[Any]): Unit = {
           JdbcUtil.insert(userRecommendSql,args)
  }

  /**
   * 批量插入
   *
   * @param args
   */
  override def storageUserRecommendByBatch(args: ListBuffer[ListBuffer[Any]]): Unit = ???


}
